/* SPDX-License-Identifier: GPL-2.0-or-later
 *
 * Copyright (C) 2016-2019, LomboTech Co.Ltd.
 * Authors:
 *	lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef _LOMBO_DRV_H_
#define _LOMBO_DRV_H_

#define G2D_NEW_DRV 1

#define LOMBO_FBDEV_MAX	2
struct device;
struct drm_fbdev_cma;
struct seq_file;
struct lombo_wb;
struct lombo_wb_funcs;

struct lombo_boot_disp {

	/* boot_fb info */
	uint64_t phy_addr;
	uint32_t fmt; /* drm fourcc */
	uint32_t width;
	uint32_t height;
	uint32_t pitch; /* uint: bytes */

	/* region of boot_fb to copy */
	uint32_t copy_x;
	uint32_t copy_y;
	uint32_t copy_w;
	uint32_t copy_h;
	/* position of boot_fb on screen */
	uint32_t scn_x;
	uint32_t scn_y;
	uint32_t scn_w;
	uint32_t scn_h;

	/* VO info*/
	uint32_t output_type;
	uint32_t output_mode;
	uint32_t output_w;
	uint32_t output_h;

	/* display pipe */
	uint32_t win_id;
	uint32_t dc_id;
	uint32_t tcon_id;
	void *crtc; /* masked at crtc init */

};

struct lombo_pipeline {
	int output_dev_cnt;
	struct drm_connector *con[LOMBO_FBDEV_MAX];
};

struct lombo_drv {
	struct device *dpu_top;
	struct device *vgss_top;

	int fbdev_cnt;
	struct drm_fb_helper **fbdev;
	struct lombo_pipeline *pipeline;
	struct drm_connector *possible_cons[LOMBO_FBDEV_MAX];
	int fb_bpp[LOMBO_FBDEV_MAX];
	uint8_t fb_win_id[LOMBO_FBDEV_MAX]; /* win_id of dc for fb */
	uint8_t has_scale; /* set by se */
	uint8_t deferred_restore;
	uint8_t skip_boot;

	struct lombo_wb *wb;
	struct lombo_wb_funcs *wb_funcs;

	struct lombo_boot_disp *boot_disp;
};

/* lombo_drm_open should use it belowly. */
struct lombo_file_private {
	void *dit_fpriv; /* for dit file private */
	void *rot_fpriv; /* for rot file private */
	void *scale_fpriv; /* for scale file private */
	void *g2d_fpriv; /* for g2d file private */

	int ignore_ioctl_permit;
};

static inline int lombo_disp_boot_sync(struct drm_crtc *crtc)
{
	struct lombo_drv *drv = crtc->dev->dev_private;
	struct lombo_boot_disp *bd = drv->boot_disp;

	if (drv->skip_boot || (bd && bd->crtc && (bd->crtc == crtc)))
		return 1;
	return 0;
}

static inline void lombo_skip_boot_set(struct drm_crtc *crtc,
						uint8_t skip_boot)
{
	struct lombo_drv *drv = crtc->dev->dev_private;

	drv->skip_boot = skip_boot;
}

int lombo_disp_boot_sync_id(struct lombo_drv *drv,
		const char *name, uint32_t id);
extern int lombo_crtc_kms_show(struct seq_file *m, void *data);

#endif /* #ifndef _LOMBO_DRV_H_ */
